package offer;

/**
 * <p>
 * 剑指 Offer 22. 链表中倒数第k个节点
 * </p>
 *
 * @author xiaozuolin
 * @date 2021/9/23 14:59
 */
public class Offer22 {

    public static ListNode getKthFromEnd(ListNode head, int k) {
        ListNode former = head;
        ListNode latter = head;
        for (int i = 0; i < k; i++) {
            former = former.next;
        }
        while (former != null) {
            former = former.next;
            latter = latter.next;
        }
        return latter;
    }
}
